/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * homeFrame.java
 *
 * Created on Jul 9, 2014, 2:58:12 PM
 */
package searchspads;

import java.awt.BorderLayout;
import java.awt.Desktop;
import java.awt.Font;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Properties;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
import org.icepdf.core.views.DocumentViewController;
import org.icepdf.ri.common.ComponentKeyBinding;
import org.icepdf.ri.common.SwingController;
import org.icepdf.ri.common.SwingViewBuilder;
import org.icepdf.ri.common.views.DocumentViewControllerImpl;

/**
 *
 * @author User
 */
public class homeFrame extends javax.swing.JFrame {
private ContactEditor contact;
    /** Creates new form homeFrame */
    public homeFrame() {
        
        initComponents();
       // setCurrentLanguage();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        titlelbright = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        exitbtn = new javax.swing.JButton();
        languagebtn = new javax.swing.JButton();
        accesscampusbtn = new javax.swing.JButton();
        schedulebtn = new javax.swing.JButton();
        aboutbtn = new javax.swing.JButton();
        awardbtn = new javax.swing.JButton();
        otherbtn = new javax.swing.JButton();
        programbtn = new javax.swing.JButton();
        searchmultibtn = new javax.swing.JButton();
        searchroombtn = new javax.swing.JButton();
        titlelbleft = new javax.swing.JLabel();
        banner_header_img = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBounds(new java.awt.Rectangle(0, 0, 0, 0));
        setMinimumSize(new java.awt.Dimension(1000, 700));

        jPanel1.setMaximumSize(new java.awt.Dimension(1000, 700));
        jPanel1.setMinimumSize(new java.awt.Dimension(1000, 700));
        jPanel1.setPreferredSize(new java.awt.Dimension(1000, 700));
        jPanel1.setLayout(null);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/app_pdf.png"))); // NOI18N
        jButton1.setMaximumSize(new java.awt.Dimension(42, 21));
        jButton1.setMinimumSize(new java.awt.Dimension(42, 21));
        jButton1.setPreferredSize(new java.awt.Dimension(42, 21));
        jPanel1.add(jButton1);
        jButton1.setBounds(804, 200, 42, 21);

        titlelbright.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/app_tittle_02.png"))); // NOI18N
        jPanel1.add(titlelbright);
        titlelbright.setBounds(430, 170, 230, 30);

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/App_20.png"))); // NOI18N
        jLabel2.setText("jLabel2");
        jLabel2.setPreferredSize(new java.awt.Dimension(582, 22));
        jPanel1.add(jLabel2);
        jLabel2.setBounds(210, 560, 582, 22);

        exitbtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/end_button.png"))); // NOI18N
        exitbtn.setText("Exit");
        exitbtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        exitbtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                actionExitClick(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                exitbtnMouseExited(evt);
            }
        });
        jPanel1.add(exitbtn);
        exitbtn.setBounds(850, 490, 113, 44);

        languagebtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/English_Button.png"))); // NOI18N
        languagebtn.setText("English");
        languagebtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        languagebtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                actionClickLaunguage(evt);
            }
        });
        languagebtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                languagebtnActionPerformed(evt);
            }
        });
        jPanel1.add(languagebtn);
        languagebtn.setBounds(860, 150, 113, 40);

        accesscampusbtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/App_Program.png"))); // NOI18N
        accesscampusbtn.setText("jButton3");
        accesscampusbtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jPanel1.add(accesscampusbtn);
        accesscampusbtn.setBounds(450, 220, 397, 36);

        schedulebtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/App_Program.png"))); // NOI18N
        schedulebtn.setText("jButton4");
        schedulebtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        schedulebtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                schedulebtnActionPerformed(evt);
            }
        });
        jPanel1.add(schedulebtn);
        schedulebtn.setBounds(450, 260, 397, 36);

        aboutbtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/App_Program.png"))); // NOI18N
        aboutbtn.setText("jButton5");
        aboutbtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jPanel1.add(aboutbtn);
        aboutbtn.setBounds(450, 300, 397, 36);

        awardbtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/App_Program.png"))); // NOI18N
        awardbtn.setText("jButton6");
        awardbtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jPanel1.add(awardbtn);
        awardbtn.setBounds(450, 340, 397, 36);

        otherbtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/App_Program.png"))); // NOI18N
        otherbtn.setText("jButton7");
        otherbtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jPanel1.add(otherbtn);
        otherbtn.setBounds(450, 380, 397, 36);

        programbtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/App_Program.png"))); // NOI18N
        programbtn.setText("jButton8");
        programbtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jPanel1.add(programbtn);
        programbtn.setBounds(450, 420, 397, 36);

        searchmultibtn.setForeground(new java.awt.Color(255, 255, 255));
        searchmultibtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/App_Search.png"))); // NOI18N
        searchmultibtn.setAlignmentY(0.0F);
        searchmultibtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        searchmultibtn.setLabel("多分野で検索");
        searchmultibtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchmultibtnActionPerformed(evt);
            }
        });
        jPanel1.add(searchmultibtn);
        searchmultibtn.setBounds(60, 220, 301, 57);

        searchroombtn.setForeground(new java.awt.Color(255, 255, 255));
        searchroombtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/App_Search.png"))); // NOI18N
        searchroombtn.setText("jButton2");
        searchroombtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        searchroombtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchroombtnActionPerformed(evt);
            }
        });
        jPanel1.add(searchroombtn);
        searchroombtn.setBounds(60, 280, 301, 57);

        titlelbleft.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/app_tittle_01.png"))); // NOI18N
        jPanel1.add(titlelbleft);
        titlelbleft.setBounds(40, 170, 204, 27);

        banner_header_img.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        banner_header_img.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/Banner_head.png"))); // NOI18N
        banner_header_img.setAlignmentY(0.0F);
        banner_header_img.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        jPanel1.add(banner_header_img);
        banner_header_img.setBounds(0, 0, 1000, 142);

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/Background.png"))); // NOI18N
        jLabel1.setAlignmentY(0.0F);
        jLabel1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        jPanel1.add(jLabel1);
        jLabel1.setBounds(0, 0, 1000, 700);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 1000, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 700, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-1010)/2, (screenSize.height-700)/2, 1010, 700);
    }// </editor-fold>//GEN-END:initComponents

private void searchmultibtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchmultibtnActionPerformed
// TODO add your handling code here:
   // new ContactEditor().setVisible(true);
    if(contact == null){
         contact = new ContactEditor();        
    }
    contact.setCurrentLangluage(languagebtn.getText());
    contact.setVisible(true);
}//GEN-LAST:event_searchmultibtnActionPerformed
// change language when click button change language.
private void setCurrentLanguage(){
    	Properties prop = new Properties();
	InputStream input = null;
	try {
                   if(languagebtn.getText().equals("English")){
                     input = getClass().getClassLoader().getResourceAsStream("resources/language_jp.properties"); 
                     titlelbleft.setIcon(new ImageIcon(this.getClass().getClassLoader().getResource("resources/images/app_tittle_01.png")));
                     titlelbright.setIcon(new ImageIcon(this.getClass().getClassLoader().getResource("resources/images/app_tittle_02.png")));
                     banner_header_img.setIcon(new ImageIcon(this.getClass().getClassLoader().getResource("resources/images/Banner_head.png")));
                     
                   }
                   else{
                       input = getClass().getClassLoader().getResourceAsStream("resources/language_en.properties"); 
                       banner_header_img.setIcon(new ImageIcon(this.getClass().getClassLoader().getResource("resources/images/app_english_headbanner.png")));
                       titlelbleft.setIcon(new ImageIcon(this.getClass().getClassLoader().getResource("resources/images/app_tittle_en_01.png")));
                       titlelbright.setIcon(new ImageIcon(this.getClass().getClassLoader().getResource("resources/images/app_tittle_en_02.png")));
                   }
		// load a properties file
		prop.load(input);
                languagebtn.setText(prop.getProperty("language"));
                
                searchmultibtn.setText(prop.getProperty("searchmulti"));
           //     searchmultibtn.setFont(new Font("Tahoma", Font.PLAIN, 11));
                searchroombtn.setText(prop.getProperty("searchroom"));
                accesscampusbtn.setText(prop.getProperty("accesscampus"));
                schedulebtn.setText(prop.getProperty("schedule"));
                aboutbtn.setText(prop.getProperty("about"));
                awardbtn.setText(prop.getProperty("award"));
                otherbtn.setText(prop.getProperty("other"));
                programbtn.setText(prop.getProperty("program"));
                exitbtn.setText(prop.getProperty("exit"));
		// get the property value and print it out
		//System.out.println(prop.getProperty("language"));

	} catch (IOException ex) {
		ex.printStackTrace();
	} finally {
		if (input != null) {
			try {
				input.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}

private void actionClickLaunguage(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_actionClickLaunguage
    setCurrentLanguage();

}//GEN-LAST:event_actionClickLaunguage

private void languagebtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_languagebtnActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_languagebtnActionPerformed


private static String getStringFromInputStream(InputStream is) {
 
        BufferedReader br = null;
        StringBuilder sb = new StringBuilder();

        String line;
        try {

                br = new BufferedReader(new InputStreamReader(is));
                while ((line = br.readLine()) != null) {
                        sb.append(line);
                }

        } catch (IOException e) {
                e.printStackTrace();
        } finally {
                if (br != null) {
                        try {
                                br.close();
                        } catch (IOException e) {
                                e.printStackTrace();
                        }
                }
        }

        return sb.toString();
 
}
private void searchroombtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchroombtnActionPerformed
    File file = new File("data/kourakuen_01.pdf");
        if(file.exists()){
            
//         if(Desktop.isDesktopSupported()){
//             try {
//                  Desktop.getDesktop().open(file);
//             } catch (Exception e) {
//             }
//         }else{
           
//         String str = new String(this.getClass().getClassLoader().getResource("resources/pdf/kourakuen_01.pdf").toExternalForm());
//         InputStream input = getClass().getClassLoader().getResourceAsStream("data/kourakuen_01.pdf"); 
         String result = "data/kourakuen_01.pdf";
         
         SwingController controller = new SwingController();
         
         controller.openFileInSomeViewer(result);
         SwingViewBuilder factory = new SwingViewBuilder(controller);
    
         controller.setIsEmbeddedComponent(true);
         // set the viewController embeddable flag.
         DocumentViewController viewController =
                 controller.getDocumentViewController();
 
         JPanel viewerComponentPanel = factory.buildViewerPanel();
         
         // add copy keyboard command
         ComponentKeyBinding.install(controller, viewerComponentPanel);
 
         // add interactive mouse link annotation support via callback
         controller.getDocumentViewController().setAnnotationCallback(
                 new org.icepdf.ri.common.MyAnnotationCallback(
                         controller.getDocumentViewController()));
         
         // build a containing JFrame for display
         JFrame applicationFrame = new JFrame();
         
         applicationFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
 
         applicationFrame.getContentPane().setLayout(new BorderLayout());
         applicationFrame.getContentPane().add(viewerComponentPanel, BorderLayout.CENTER);
         applicationFrame.getContentPane().add(factory.buildCompleteMenuBar(), BorderLayout.NORTH);
         
         // Now that the GUI is all in place, we can try opening a PDF
 
         // hard set the page view to single page which effectively give a single
         // page view. This should be done after openDocument as it has code that
         // can change the view mode if specified by the file.
         controller.setPageViewMode(
                 DocumentViewControllerImpl.ONE_PAGE_VIEW,
                 false);
 
         // show the component
         applicationFrame.pack();
         applicationFrame.setVisible(true);
//         }
        
        }   
}//GEN-LAST:event_searchroombtnActionPerformed

private void exitbtnMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_exitbtnMouseExited
// TODO add your handling code here:
  //  System.exit(1);
}//GEN-LAST:event_exitbtnMouseExited

private void actionExitClick(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_actionExitClick
// TODO add your handling code here:
    System.exit(1);
}//GEN-LAST:event_actionExitClick

private void schedulebtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_schedulebtnActionPerformed
     File file = new File("data/tama_01.pdf");
        if(file.exists()){
            
//         if(Desktop.isDesktopSupported()){
//             try {
//                  Desktop.getDesktop().open(file);
//             } catch (Exception e) {
//             }
//         }else{
//         
//         }
        

        
        SwingController controller = new SwingController();
         controller.openFileInSomeViewer("data/tama_01.pdf");
         SwingViewBuilder factory = new SwingViewBuilder(controller);
    
         controller.setIsEmbeddedComponent(true);
         // set the viewController embeddable flag.
         DocumentViewController viewController =
                 controller.getDocumentViewController();
 
         JPanel viewerComponentPanel = factory.buildViewerPanel();
         
         // add copy keyboard command
         ComponentKeyBinding.install(controller, viewerComponentPanel);
 
         // add interactive mouse link annotation support via callback
         controller.getDocumentViewController().setAnnotationCallback(
                 new org.icepdf.ri.common.MyAnnotationCallback(
                         controller.getDocumentViewController()));
         
         // build a containing JFrame for display
         JFrame applicationFrame = new JFrame();
         
         applicationFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
 
         applicationFrame.getContentPane().setLayout(new BorderLayout());
         applicationFrame.getContentPane().add(viewerComponentPanel, BorderLayout.CENTER);
         applicationFrame.getContentPane().add(factory.buildCompleteMenuBar(), BorderLayout.NORTH);
         
         // Now that the GUI is all in place, we can try opening a PDF
 
         // hard set the page view to single page which effectively give a single
         // page view. This should be done after openDocument as it has code that
         // can change the view mode if specified by the file.
         controller.setPageViewMode(
                 DocumentViewControllerImpl.ONE_PAGE_VIEW,
                 false);
 
         // show the component
         applicationFrame.pack();
         applicationFrame.setVisible(true);
        }
}//GEN-LAST:event_schedulebtnActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(homeFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(homeFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(homeFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(homeFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new homeFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton aboutbtn;
    private javax.swing.JButton accesscampusbtn;
    private javax.swing.JButton awardbtn;
    private javax.swing.JLabel banner_header_img;
    private javax.swing.JButton exitbtn;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton languagebtn;
    private javax.swing.JButton otherbtn;
    private javax.swing.JButton programbtn;
    private javax.swing.JButton schedulebtn;
    private javax.swing.JButton searchmultibtn;
    private javax.swing.JButton searchroombtn;
    private javax.swing.JLabel titlelbleft;
    private javax.swing.JLabel titlelbright;
    // End of variables declaration//GEN-END:variables
}
